#include "power_debuff.h"

CPowerDebuff::CPowerDebuff()
    : CBuff(ENT_DEBUFF_POWER,
            "buff_depower",
            BUFF_TYPE_DEBUFF)     
{
    
}

bool CPowerDebuff::applyBuff(CPlayer *pPlayer)
{
    /**
     * Applies this debuff to a specific player. This debuff decreases the power
     * of the weapon by 1.
     * 
     * @param CPlayer *pPlayer The player to apply the buff to.
     * @return bool Whether the debuff was applied
     */
    if (pPlayer->getActiveWeapon() != nullptr)
    {
        if (pPlayer->getActiveWeapon()->getID() == ENT_WEAPON_BOMB)
        {
            CBomb *pBomb(dynamic_cast<CBomb*>(pPlayer->getActiveWeapon()));
            if (pBomb->getExplodeRadius() > 1)
            {
                pBomb->setExplodeRadius(
                    pBomb->getExplodeRadius() - 1);
                return true;
            }
        }
    }
    return false;
}

bool CPowerDebuff::removeBuff(CPlayer *pPlayer)
{
    /**
     * Removes this debuff from a specific player. This increases the power
     * of the weapon by 1.
     * 
     * @param CPlayer *pPlayer The player to remove the debuff from.
     * @return bool Whether the buff was removed
     */
    if (pPlayer->getActiveWeapon())
    {
        if (pPlayer->getActiveWeapon()->getID() == ENT_WEAPON_BOMB)
        {
            CBomb *pBomb(dynamic_cast<CBomb*>(pPlayer->getActiveWeapon()));
            pBomb->setExplodeRadius(
                pBomb->getExplodeRadius() + 1);
            return true;
        }
    }
    return false;
}